﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Basic4Net.BusinessRules;
using Basic4Net.OAWeb.Base;
using System.Data;
using Basic4Net.Utility.Common;

namespace Basic4Net.OAWeb.Module_Report
{
	public partial class HolidayWorkReport : BasePage
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!IsPostBack)
			{
				ReportYearBR br = new ReportYearBR();
				ddl_Term.DataSource = br.GetHolidayList(); ;
				ddl_Term.DataTextField = "String";
				ddl_Term.DataValueField = "Value";
				ddl_Term.DataBind();

				GridBind();
			}
		}

		public void GridBind()
		{
			//ReportYearBR br = new ReportYearBR();

			//object list = br.GetHolidayWorkList(Convert.ToInt32(ddl_Term.SelectedValue.Split('-')[0]), Convert.ToInt32(ddl_Term.SelectedValue.Split('-')[1]));

			//pRepeater.DataSource = list;
			//pRepeater.DataBind();
			ReportYearBR br = new ReportYearBR();
            int year = 0;
            int month =0;
            if (ddl_Term.SelectedValue.Split('-').Count() >= 2)
            {
                 year = Convert.ToInt32(ddl_Term.SelectedValue.Split('-')[0]);
                 month = Convert.ToInt32(ddl_Term.SelectedValue.Split('-')[1]);
            }
            var list = br.GetHolidayWorkList(ExistSuper((int)(Session["UserID"] ?? -1)), (int)(Session["UserID"] ?? -1), year, month);

			DataTable dt = new DataTable();
			Common.IListToTable(dt, new HolidayWorkReportShow());
			var mylist = list;
			for (int i = 0; i < mylist.Count; i++)
			{
				DataRow row = dt.NewRow();
				row["ID"] = mylist[i].ID;
				row["Name"] = mylist[i].Name;
				row["Remark"] = mylist[i].Remark;
				row["Value"] = mylist[i].Value;
				row["Code"] = mylist[i].Code;
				dt.Rows.Add(row);
			}

			//------------------------------------------------------------------------分页处理开始......
			int PageNow = 0;
			DataView dv = dt.DefaultView;
			System.Web.UI.WebControls.PagedDataSource ps = new PagedDataSource();
			ps.DataSource = dv;
			ps.AllowPaging = true;
			ps.PageSize = 20;
			if (this.txt_Go.Text.ToString() == "")
				this.txt_Go.Text = "1";
			if (this.txt_Go.Text.ToString() == "0")
				this.txt_Go.Text = "1";
			if (Convert.ToInt32(this.txt_Go.Text.ToString()) >= ps.PageCount)
				this.txt_Go.Text = ps.PageCount.ToString();
			PageNow = Convert.ToInt32(this.txt_Go.Text.ToString()) - 1;

			ps.CurrentPageIndex = Convert.ToInt32(this.txt_Go.Text.ToString()) - 1;
			//-------------------------------------------------------------------------分页处理结束

			pRepeater.DataSource = ps;
			pRepeater.DataBind();

			//------------------------------------------------------------------------记录总数、当前页数、总页数处理开始......
			//this.lbl_SumCount.Text = ds.Tables[0].Rows.Count.ToString();
			this.lbl_ToPage.Text = this.txt_Go.Text.ToString();
			this.lbl_PageCount.Text = ps.PageCount.ToString();

			//------------------------------------------------------------------------------记录总数、当前页数、总页数处理结束
		}

		protected void btnBind_Click(object sender, EventArgs e)
		{
			GridBind();
		}

		protected void ddl_Term_SelectedIndexChanged(object sender, EventArgs e)
		{
			GridBind();
		}
	}
}